{{extend 'zlayout.html'}}

{{if view_info['errors']:}}
    <p class="err">{{=XML(T('There was one or more errors while processing your request, please correct the following'))}}</p>
    <ul>
        {{for error in view_info['errors']:}}
            <li class="err">{{=XML(T(error))}}</li>
        {{pass}}
    </ul>
{{pass}}

<div class="breadcrumbs">
    <a href="{{=URL(r=request, c='default', f='index')}}" title="{{=XML(T('Home'))}}">{{=XML(T('Home'))}}</a><span
       class="sep"> / </span><a href="{{=URL(r=request, c='default', f='view_forum', args=[forum.id])}}"
       title="{{=XML(T('Back To'))}} {{=forum.forum_title}}">{{=forum.forum_title}}</a><span
       class="sep"> / </span><b>{{=XML(parse_content(topic.title))}}</b>
    {{if view_info['subscribed_to_topic']:}}<i>({{=XML(T('You are subscribed to this topic'))}})</i>{{pass}}
</div>

<div class="subnav">
    <a href="{{=URL(r=request, c='default', f='view_forum', args=[forum.id])}}"
        title="{{=XML(T('Back To'))}} {{=forum.forum_title}}">{{=XML(T('Back'))}}</a>
    {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}
        <span class="sep">|</span>
        <a href="#add_comment" title="{{=XML(T('Add a Topic Response'))}}">{{=XML(T('Add a Topic Response'))}}</a>
    {{pass}}
    {{if auth_user.is_auth():}}
        <span class="sep">|</span>
        {{if view_info['subscribed_to_topic']:}}
            <a href="{{=URL(r=request, c='default', f='view_topic', args=[topic.id, 0])}}" title="{{=XML(T('Unsubscribe from Topic'))}}">{{=XML(T('Unsubscribe from Topic'))}}</a>
        {{else:}}
            <a href="{{=URL(r=request, c='default', f='view_topic', args=[topic.id, 1])}}" title="{{=XML(T('Subscribe to Topic'))}}">{{=XML(T('Subscribe to Topic'))}}</a>
        {{pass}}
    {{pass}}
</div>

<div>{{=XML(view_info['pagination_widget'])}}</div>

<form id="topics_form" method="post" name="topics_form" action="">
    <fieldset id="topics_form_fields">
        <input type="hidden" id="topic_id" name="topic_id" value="{{=topic.id}}" />
        <input type="hidden" id="forum_id" name="forum_id" value="{{=forum.id}}" />
        <input type="hidden" id="form_submitted" name="form_submitted" value="1" />
        <input type="hidden" id="action" name="action" value="remove" />
        <input type="hidden" id="confirm_delete_msg" name="confirm_delete_msg" value="{{=XML(T('Please confirm the removal of the selected topics'))}}" />
        <input type="hidden" id="warn_delete_parent_msg" name="warn_delete_parent_msg" value="{{=XML(T('Warning: Removing this topic will remove all its sibling topics'))}}" />
        <input type="hidden" id="confirm_inapp" name="confirm_inapp" value="{{=XML(T('Please confirm you wish to report this topic as inappropriate'))}}" />
        <input type="hidden" id="c" name="c" value="{{=view_info['anon_captcha_base64']}}" />

        {{if view_info.has_key('preview'):}}
            <div class="preview">
                <b>{{=XML(T('Message Preview'))}}</b>
                <div class="hr"><hr /></div>
                <div>{{=XML(parse_content(request.vars.get('response_content', ''), mode='forumfull'))}}</div>
                <a href="#add_comment" title="{{=XML(T('Add This Comment'))}}">{{=XML(T('Add This Comment'))}}</a>
            </div>
        {{pass}}

        {{if auth_user.is_admin():}}
            <div class="bottom-separator">
                <input type="submit" id="submit_del" name="remove" value="Remove Checked Topics" onclick="return confirm(document.getElementById('confirm_delete_msg').value);" />
            </div>
        {{pass}}

        <table cellspacing="0" cellpadding="0" class="zf-table" class="max-width" style="width:100%;">
            <thead>
                <tr class="shadedarker">
                    <td class="cell3d" colspan="2" class="max-width"><b>{{=topic.title}}</b></td>
                </tr>
            </thead>
            <tbody>
                <tr class="shadedarker">
                    <td class="cell3d" style="width:15%;">
                        <div class="topic-information">
                            {{=XML(T('By'))}}:
                            {{if topic.creation_user == 'Anonymous User':}}
                                <b class="small">Anonymous User</b>
                            {{else:}}
                                {{if auth_user.is_auth():}}
                                    <a href="{{=URL(r=request, c='pm', f='message_new', args=[topic.creation_user])}}"
                                       title=""
                                       class="smallb">{{=topic.creation_user}}</a>
                                {{else:}}
                                    <b>{{=topic.creation_user}}</b>
                                {{pass}}
                                {{if forumhelper.get_system_property('zfsp_use_ranking_system', '') != '':}}
                                    <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(topic.creation_user)}}
                                {{pass}}
                                <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', topic.creation_user, '0')}}
                                <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', topic.creation_user, XML(T('<i>Unknown</i>')))}}
                                {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(topic.creation_user):}}
                                    <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[topic.creation_user])}}" alt="" />
                                {{pass}}
                            {{pass}}
                        </div>
                    </td>
                    <td class="cell3d">
                        <div style="float:left;" class="topic-information">
                            <a id="{{=topic.id}}">{{=XML(T('Posted'))}}</a>:
                            {{=XML(T(str(topic.creation_date.strftime('%a, %d %B, %Y - %I:%M %p'))))}}
                        </div>
                        <div style="float:right;" class="topic-information">
                            {{if auth_user.is_admin():}}
                                <a href="{{=URL(r=request, c='default', f='edit_topic', args=[topic.id])}}"
                                   title="{{=XML(T('Edit Topic'))}}">{{=XML(T('Edit Topic'))}}</a> |
                            {{pass}}
                            {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}
                                <a href="#add_comment"
                                   title=""
                                   onclick="reply_quote('{{=topic.creation_user}}', 'topic_id_{{=topic.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
                            {{pass}}
                            <a href="{{=URL(r=request, c='default', f='report_inappropriate', args=[topic.id, topic.id])}}"
                               onclick="return confirm(document.getElementById('confirm_inapp').value);"
                               title="{{=XML(T('Report as inappropriate'))}}">{{=XML(T('Report as inappropriate'))}}</a>
                            {{if auth_user.is_admin():}}
                                |
                                <input type="checkbox" id="remove_topic_parent_{{=topic.id}}"
                                       name="remove_topic_parent_{{=topic.id}}"
                                       value="{{=topic.id}}"
                                       onclick="if(this.checked){alert(document.getElementById('warn_delete_parent_msg').value);}"
                                       style="vertical-align:middle;" />
                                <label for="remove_topic_parent_{{=topic.id}}" style="font-weight:bold;">{{=XML(T('Remove Topic'))}}</label>
                            {{pass}}
                        </div>
                        <div class="hr" style="clear:both;"><hr /></div>
                        <div id="topic_id_{{=topic.id}}" class="both-separator">{{=XML(parse_content(topic.content, mode='forumfull'))}}</div>
                    </td>
                </tr>
                {{if len(children):}}
                    {{for row, this_child in enumerate(children):}}
                        <tr class="{{if row%2:}}shadedark{{else:}}shadelight{{pass}}">

                            <td class="cell3d" style="width:15%;">
                                <div class="topic-information">
                                    {{=XML(T('By'))}}:
                                    {{if this_child.creation_user == 'Anonymous User':}}
                                        <b class="small">Anonymous User</b>
                                    {{else:}}
                                        {{if auth_user.is_auth():}}
                                            <a href="{{=URL(r=request, c='pm', f='message_new', args=[this_child.creation_user])}}"
                                               title="">{{=this_child.creation_user}}</a>
                                        {{else:}}
                                            <b>{{=this_child.creation_user}}</b>
                                        {{pass}}
                                        {{if forumhelper.get_system_property('zfsp_use_ranking_system', '') != '':}}
                                            <br />{{=XML(T('Rank'))}}: {{=forumhelper.get_user_rank(this_child.creation_user)}}
                                        {{pass}}
                                        <br />{{=XML(T('Postings'))}}: {{=forumhelper.get_member_property('zfmp_postings', this_child.creation_user, '0')}}
                                        <br />{{=XML(T('From'))}}: {{=forumhelper.get_member_property('zfmp_country', this_child.creation_user, XML(T('<i>Unknown</i>')))}}
                                        {{if forumhelper.get_system_property('zfsp_allow_member_avatars', '') != '' and forumhelper.has_member_avatar(this_child.creation_user):}}
                                            <img src="{{=URL(r=request, c='zadmin', f='get_avatar_image', args=[this_child.creation_user])}}" alt="" />
                                        {{pass}}
                                    {{pass}}
                                </div>
                            </td>
                            <td class="cell3d">
                                <div style="float:left;" class="topic-information">
                                    <a id="{{=this_child.id}}">{{=XML(T('Posted'))}}</a>:
                                    {{=XML(T(str(this_child.creation_date.strftime('%a, %d %B, %Y - %I:%M %p'))))}}
                                </div>
                                <div style="float:right;" class="topic-information">
                                    {{if auth_user.is_admin():}}
                                        <a href="{{=URL(r=request, c='default', f='edit_topic', args=[this_child.id])}}" title="{{=XML(T('Edit Topic'))}}">{{=XML(T('Edit Topic'))}}</a> |
                                    {{pass}}
                                    {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}
                                        <a href="#add_comment"
                                           title=""
                                           onclick="reply_quote('{{=this_child.creation_user}}', 'topic_id_{{=this_child.id}}');">{{=XML(T('Reply w/Quote'))}}</a> |
                                    {{pass}}
                                    <a href="{{=URL(r=request, c='default', f='report_inappropriate', args=[this_child.id, topic.id])}}"
                                       onclick="return confirm(document.getElementById('confirm_inapp').value);"
                                       title="{{=XML(T('Report as inappropriate'))}}">{{=XML(T('Report as inappropriate'))}}</a>
                                    {{if auth_user.is_admin():}}
                                        |
                                        <input type="checkbox" id="remove_topic_child_{{=this_child.id}}"
                                               name="remove_topic_child_{{=this_child.id}}"
                                               value="{{=this_child.id}}"
                                               style="vertical-align:middle;" />
                                        <label for="remove_topic_child_{{=this_child.id}}"
                                               style="font-weight:bold;">{{=XML(T('Remove Topic'))}}</label>
                                    {{pass}}
                                </div>
                                <div class="hr" style="clear:both;"><hr /></div>
                                <div id="topic_id_{{=this_child.id}}" class="both-separator">{{=XML(parse_content(this_child.content, mode='forumfull'))}}</div>
                            </td>
                        </tr>
                    {{pass}}
                {{pass}}
            </tbody>
        </table>

        {{if not len(children):}}
            <p class="information" style="font-style:italic;text-align:center;">{{=XML(T('This topic contains no responses'))}}.</p>
        {{pass}}

        {{if topic.locked_flag:}}
            <p class="information" style="font-style:italic;text-align:center;">{{=XML(T('The forum administrator has restricted adding any more comments to this topic'))}}.</p>
        {{pass}}

        {{if (security_info['can_reply'] and not topic.locked_flag) or auth_user.is_admin():}}

            <div class="both-separator">
                <a id="add_comment" name="add_comment">&nbsp;</a>

                <table cellspacing="0" cellpadding="0" class="zf-table" style="margin-left:auto;margin-right:auto;width:90%;">
                    <thead>
                        <tr class="shadedarker">
                            <th colspan="2" class="cell3d">{{=XML(T('Add Reply'))}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="shadedarker">
                            <td class="cell3d">{{=XML(T('Title'))}}:</td>
                            <td class="cell3d"><b>{{=topic.title}}</b></td>
                        </tr>
                        <tr class="shadedarker">
                            <td class="cell3d">{{=XML(T('By'))}}:</td>
                            <td class="cell3d">{{=auth_user.get_user_name()}}, {{=XML(T('on'))}} {{=XML(T(str(request.now.strftime('%A, %d %B, %Y'))))}}</td>
                        </tr>
                        <tr class="shadedarker">
                            <td class="cell3d" style="vertical-align:middle;">{{=XML(T('Contents'))}}:</td>
                            <td class="cell3d">
                                <textarea name="response_content"
                                          id="z_content"
                                          style="width:98%;height:200px;">{{=request.vars.get('response_content', '')}}</textarea>
                            </td>
                        </tr>
                        {{if not auth_user.is_auth():}}
                            <tr class="shadedarker">
                                <td class="cell3d"><span class="required">*</span>
                                    {{=XML(T('Verify your humanity'))}}:
                                </td>
                                <td class="cell3d">
                                    <input type="text" id="captcha_response" name="captcha_response" value="" style="width:100px;" />
                                    <b>{{=view_info['anon_captcha']}}</b>
                                    <span class="warning">({{=XML(T('Please Enter the acces code shown in order to post your message'))}}.)</span>
                                </td>
                            </tr>
                        {{pass}}
                        <tr class="shadedarker">
                            <td class="cell3d" style="text-align:center;" colspan="2">
                                {{=XML(T('Click on an emoticon to add it'))}}:
                                {{for icon in view_info['emoticons']:}}
                                    <img src="{{=URL(r=request, c='static/images', f=icon)}}" alt="{{=icon[5:icon.rfind('.')]}}" class="imgclear" style="width:16px;height:16px;"
                                         onmouseover="this.style.cursor='pointer';"
                                         onmouseout="this.style.cursor='default';"
                                         onclick="add_emoticon('{{=icon[5:icon.rfind('.')]}}');" />
                                {{pass}}
                            </td>
                        </tr>
                        <tr class="shadedarker">
                            <td class="cell3d" style="text-align:right;" colspan="2">
                                <input type="submit" id="preview" name="preview" value="{{=XML(T('Preview'))}}" />
                                <input type="submit" id="add" name="add" value="{{=XML(T('Add'))}}" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        {{pass}}

    </fieldset>
</form>

<script type="text/javascript">
<!--
    function quote(blockquote, topic_id) {
        var blockquote;
        var response_form = document.forms['response_form'];
        var current_content = response_form['content'];
        var new_content = current_content.value + blockquote;
        var reply_to_topic_id = document.getElementById('reply_to_topic_id');
        reply_to_topic_id.value = topic_id;
        current_content.value = new_content;
        current_content.focus();
        return false;
    }

    function toggle_thread(element_id) {
        var displaystyle = document.getElementById(element_id).style;
        if (displaystyle.display == 'none') {
            displaystyle.display = 'block';
        } else {
            displaystyle.display = 'none';
        }
        return false;
    }

    function add_emoticon(e_value) {
        var emoticon_value = ':' + e_value + ':';
        var my_field = document.getElementById('z_content');

        //IE support
        if (document.selection) {
            my_field.focus();
            sel = document.selection.createRange();
            sel.text = emoticon_value;
        }
        //MOZILLA/NETSCAPE support
        else if (my_field.selectionStart || my_field.selectionStart == 0) {
            var start_pos = my_field.selectionStart;
            var end_pos = my_field.selectionEnd;
            my_field.value = my_field.value.substring(0, start_pos) + emoticon_value + my_field.value.substring(end_pos, my_field.value.length);
        } else {
            my_vield.value += emoticon_value;
        }

        document.getElementById('z_content').focus();
    }
    
    function reply_quote(username, topic_id_text) {
        var topic_text = document.getElementById(topic_id_text).innerHTML;
        topic_text = topic_text.replace(/<br>/g, '\n');
        var quote_text = '\n\n[quote][smallb]From: ' + username + '[/smallb]\n\n' + topic_text + '\n[/quote]';
        document.getElementById('z_content').value = quote_text;
        document.getElementById('z_content').focus();  
    }
//-->
</script>
